//
//  PKTabbarController.m
//  Fanke
//
//  Created by sharayuki on 2017/8/12.
//  Copyright © 2017年 sharayuki. All rights reserved.
//

#import "PKTabbarController.h"
#import "PKBaseViewController.h"
#import "PKNavigationController.h"
#import "PKBaseViewController.h"
#import "PKLiveController.h"
#import "PKMainController.h"
#import "PKMineController.h"
@interface PKTabbarController ()

@end

@implementation PKTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSMutableArray *mub = [NSMutableArray array];
    
    [mub addObject:[self childControllerWithClsName:@"PKMainController" andTitle:@"" andImgName:@"tab_home"]];
    
    [mub addObject:[self childControllerWithClsName:@"PKLiveController" andTitle:@"" andImgName:@"tab_publish"]];
    
    [mub addObject:[self childControllerWithClsName:@"PKMineController" andTitle:@"" andImgName:@"tab_mine"]];
    
    self.viewControllers = mub.copy;
    
    self.tabBar.tintColor = [UIColor blackColor];
    
    self.tabBar.barTintColor = [UIColor whiteColor];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//创建子控制器
- (PKNavigationController *)childControllerWithClsName:(NSString *)clsName andTitle:(NSString *)title andImgName:(NSString *)imgName{
    
    Class cls = NSClassFromString(clsName);
    
    PKBaseViewController *vc = [[cls alloc]init];
    
    vc.title = title;
    
    [vc.tabBarItem setImage:[UIImage imageNamed:imgName]];
    
    vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"%@-1",imgName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [vc.tabBarItem setSelectedImage:image];
    PKNavigationController *nav = [[PKNavigationController alloc]initWithRootViewController:vc];
    
    return nav;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
